/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Client.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingConstants;

/**
 *
 * @author Ripper
 */
public class LevelUpAttributePanel extends ClientPanel implements ActionListener
{

    private JLabel playerNameLabel;
    private JLabel playerPointsAvailableLabel;
    private JLabel playerLevelLabel;
    private JProgressBar playerExpBar;
    
    private JButton returnButton;
    
    private JPanel tableContainer;
    private JButton[] spendPointButtons;
    private JLabel[] viewBonusLabels;
    private JLabel[] viewPointsSpentLabels;
    private JLabel[] currentTotalBonusLabels;
    private JLabel[] maximumPointsSpentLabels;
    private JLabel[] descriptionLabels;
    private String[] titles = {"spend point?","benefit:","point spent:","current bonus:","max:","description:"};
    
    private SexualHealing sexyNess;
    
    public LevelUpAttributePanel(ClientWindow cw)
    {
        super(cw);
        setLayout(new BorderLayout());
        
        JPanel top = new JPanel(new BorderLayout());
        {
            JPanel topPanel = new JPanel(new GridLayout(2,1));
            {
                JPanel toptopPanel = new JPanel(new BorderLayout());
                {
                    playerNameLabel = new JLabel("Player: <No player selected>");
                    toptopPanel.add(playerNameLabel, BorderLayout.CENTER);
                    playerLevelLabel = new JLabel("Level: ");
                    toptopPanel.add(playerLevelLabel, BorderLayout.EAST);
                }
                topPanel.add(toptopPanel);
                
                playerExpBar = new JProgressBar();
                playerExpBar.setMinimum(0);
                playerExpBar.setMaximum(100);
                playerExpBar.setValue(100);
                playerExpBar.setForeground(Color.GREEN);
                playerExpBar.setBackground(Color.ORANGE);
                topPanel.add(playerExpBar);
            }
            top.add(topPanel, BorderLayout.CENTER);
        }
        add(top, BorderLayout.NORTH);
        JPanel mid = new JPanel(new BorderLayout());
        {
            String[] a = new String[0];
            tableContainer = new JPanel(new GridLayout(15, titles.length));
            recreateTable(a);
            mid.add(tableContainer, BorderLayout.CENTER);
        }
        add(mid, BorderLayout.CENTER);
        JPanel bot = new JPanel(new BorderLayout());
        {
            playerPointsAvailableLabel = new JLabel("attribute points available: ");
            bot.add(playerPointsAvailableLabel, BorderLayout.CENTER);
            
            returnButton = new JButton("Return");
            returnButton.addActionListener(this);
            bot.add(returnButton, BorderLayout.EAST);
        }
        add(bot, BorderLayout.SOUTH);
    }

    @Override
    public void actionPerformed(ActionEvent e) 
    {
        if(e.getSource() == returnButton)
        {
            getClientWindow().gotoWelcomeScreen();
        }
    }
    
    public void fillWithData(String playerName, int level, int xpPrct, int attributepointsavailable, String[] data)
    {
        playerNameLabel.setText(" Player: "+playerName);
        playerLevelLabel.setText("Level: "+level+"   ");
        playerExpBar.setValue(xpPrct);
        playerPointsAvailableLabel.setText(" Available points to spend: "+attributepointsavailable);
        
        recreateTable(data);
    }
    public void recreateTable(String[] data)
    {
        tableContainer.removeAll();
        {
            spendPointButtons = new JButton[data.length];
            viewBonusLabels = new JLabel[data.length];
            viewPointsSpentLabels = new JLabel[data.length];
            currentTotalBonusLabels = new JLabel[data.length];
            maximumPointsSpentLabels = new JLabel[data.length];
            descriptionLabels = new JLabel[data.length];
            
            for(int a = 0; a < titles.length;a++)
            {
                JLabel it = new JLabel(titles[a]);
                it.setHorizontalAlignment(SwingConstants.CENTER);
                tableContainer.add(it);
                
            }
            
            sexyNess = new SexualHealing();
            for(int a = 0; a < data.length; a++)
            {
                spendPointButtons[a] = new JButton(" + ");
                spendPointButtons[a].addActionListener(sexyNess);
                tableContainer.add(spendPointButtons[a]);
                
                String[] bits = data[a].split(",");
                
                viewBonusLabels[a] = new JLabel("+"+bits[0]);
                viewBonusLabels[a].setHorizontalAlignment(SwingConstants.CENTER);
                tableContainer.add(viewBonusLabels[a]);
                
                viewPointsSpentLabels[a] = new JLabel(bits[1]);
                viewPointsSpentLabels[a].setHorizontalAlignment(SwingConstants.CENTER);
                tableContainer.add(viewPointsSpentLabels[a]);
                
                currentTotalBonusLabels[a] = new JLabel("+"+bits[2]);
                currentTotalBonusLabels[a].setHorizontalAlignment(SwingConstants.CENTER);
                tableContainer.add(currentTotalBonusLabels[a]);
                
                maximumPointsSpentLabels[a] = new JLabel(bits[3]);
                maximumPointsSpentLabels[a].setHorizontalAlignment(SwingConstants.CENTER);
                tableContainer.add(maximumPointsSpentLabels[a]);
                
                descriptionLabels[a] = new JLabel(bits[4]);
                tableContainer.add(descriptionLabels[a]);
            }
            
            
        }
    }
    
    private class SexualHealing implements ActionListener
    {
        public SexualHealing() 
        {
            
        }

        @Override
        public void actionPerformed(ActionEvent e) 
        {
            for(int a = 0; a < spendPointButtons.length;a++)
            {
                if(e.getSource() == spendPointButtons[a])
                {
                    getClientWindow().levelupAttributePoint(a);
                }
            }
        }
    }
}
